package com.ljx.itbbs.server.user.dao;

import com.ljx.itbbs.server.user.domain.entity.PermsEntity;
import com.ljx.itbbs.server.user.domain.vo.req.PermsUpdateReq;
import com.ljx.itbbs.server.user.domain.vo.resp.PermsResp;
import com.ljx.itbbs.server.user.mapper.PermsMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 权限表 服务实现类
 * </p>
 *
 * @author LiJunXi
 * @since 2024-03-02
 */
@Service
public class PermsDao extends ServiceImpl<PermsMapper, PermsEntity> {

    public Set<String> getPermission(Long uid) {
        return this.baseMapper.getPermission(uid);
    }

    public void updatePerms(PermsUpdateReq req) {
        lambdaUpdate().set(PermsEntity::getPerms, req.getPerms())
                .set(PermsEntity::getPath, req.getPath())
                .set(PermsEntity::getPermsCategoryId, req.getCategoryId())
                .set(PermsEntity::getName, req.getMenuName())
                .set(PermsEntity::getStatus, req.getStatus())
                .eq(PermsEntity::getId, req.getId())
                .update();
    }

    public List<PermsResp> getByRoleId(Long roleId) {
        return this.baseMapper.getByRoleId(roleId);
    }
}
